package com.school.service.impl;

import com.school.common.ServiceResultEnum;
import com.school.entity.Coupon;
import com.school.mapper.CouponMapper;
import com.school.service.CouponService;
import com.school.util.PageQueryUtil;
import com.school.util.PageResult;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class CouponServiceImpl implements CouponService {
    @Resource
    private CouponMapper couponMapper;

    @Override
    public PageResult getCouponPage(PageQueryUtil pageQueryUtil) {
        List<Coupon> list = couponMapper.findCouponList(pageQueryUtil);
        int totalCount = couponMapper.getTotalCouponCount(pageQueryUtil);
        PageResult pageResult = new PageResult(list, totalCount, pageQueryUtil.getLimit(), pageQueryUtil.getPage());
        return pageResult;
    }

    @Override
    public String saveCoupon(Coupon coupon) {
        if(couponMapper.insertSelective(coupon) > 0){
            return ServiceResultEnum.SUCCESS.getResult();
        }
        return ServiceResultEnum.DB_ERROR.getResult();
    }
}
